package com.o2opay.car.service;

import com.github.pagehelper.page.PageMethod;
import com.o2opay.car.common.annotation.ServiceLog;
import com.o2opay.car.common.pojo.AjaxResult;
import com.o2opay.car.common.pojo.PageAjax;
import com.o2opay.car.common.utils.AppUtil;
import com.o2opay.car.mapper.CarInfoMapper;
import com.o2opay.car.model.CarInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by tugou on 2018/1/14.
 */
@Service
public class CarInfoService extends AbstratService<CarInfo> {

    @Autowired
    private CarInfoMapper carInfoMapper;

    @ServiceLog("查询车辆信息列表")
    public PageAjax<CarInfo> queryPage(PageAjax<CarInfo> page, CarInfo car) {
        PageMethod.startPage(page.getPageNo(), page.getPageSize());
        List<CarInfo> list = carInfoMapper.queryList(car);
        return AppUtil.returnPage(list);
    }

    @ServiceLog("添加车辆")
    public AjaxResult saveCar(CarInfo car) {
        String result = null;
        CarInfo $carInfo = carInfoMapper.queryByCarNum(car.getCarNum());
        if(null == $carInfo){
            save(car);
        }
        else{
            result = "该这牌号已存在";
        }
        return AppUtil.returnObj(result);
    }
}
